<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }

        .box {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
        }

        .box>div {
            flex: 1;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="./react.js"></script>
<script src="./react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">
    // 封装ajax
    function sendAjax(url, method, data = null) {
        return new Promise((reslove, reject) => {
            $.ajax({
                url,
                method,
                data,
                // 设置数据交换类型为json
                dataType: "json",
                success(res) {
                    reslove(res)
                },
                error(err) {
                    reject(err)
                }
            })
        })
    }
    // 获取所有英雄列表
    async function getHoreList() {
        let res = await sendAjax("https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js", "get");
        console.log(res.hero)
        render(res.hero)
    }
    getHoreList();
    // 渲染函数
    function render(hero) {
        let dom = (
            <div className='box'>
                {
                    hero.map((item, index) => {
                        return (
                            <div key={index} onClick={() => {
                            // console.log(item.heroId)
                            window.location.href = './info.html?heroId=' + item.heroId
                        }}>
                            <img src={`https://game.gtimg.cn/images/lol/act/img/champion/${item.alias}.png`} alt="" />
                            <div>{item.name}</div>
                        </div>
                        )
                    })
                }
            </div>
        );
        ReactDOM.render(dom, document.getElementById("root"))
    }
    // function goInfo(heroId){
    //     console.log(heroId)
    //     return
    //     window.location.href = './info.html'
    // }
    // function getUrl(alias){
    //     return "https://game.gtimg.cn/images/lol/act/img/champion/"+alias+".png"
    // }
</script>

</html>